package com.woniu.controller;

import com.woniu.entity.StageBilling;
import com.woniu.service.StageBillingService;
import com.woniu.vo.StageBillingVO;
import com.woniu.util.ResponseData;
import com.woniu.util.ResponseEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/stageBilling")
public class StageBillingController {
    @Resource
    private StageBillingService stageBillingService;

    @GetMapping("/list")
    public ResponseData<?> getStageBillingList(
            @RequestParam(required = false) String keyword,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        List<StageBillingVO> stages = stageBillingService.getStageBillingList(keyword, pageNum, pageSize);
        return ResponseData.ok(stages);
    }

    @PostMapping("/add")
    public ResponseData<?> addStageBilling(@RequestBody StageBilling stageBilling) {
        boolean success = stageBillingService.addStageBilling(stageBilling);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }

    @DeleteMapping("/{id}")
    public ResponseData<?> deleteStageBilling(@PathVariable("id") Long id) {
        boolean success = stageBillingService.deleteStageBilling(id);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }

    @PostMapping("/update")
    public ResponseData<?> updateStageBilling(@RequestBody StageBilling stageBilling) {
        boolean success = stageBillingService.updateStageBilling(stageBilling);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }
} 